RESP
RESP(REdis Serialization Protocol) Serialization for Rust.
Implementations:
- redis-cli redis CLI.
API
extern crate resp;
use ;
Value
RESP values.
Examples
let error = Error;
let null = Null;
impl Value
fn is_null(&self) -> bool
println!; // true
println!; // true
println!; // false
fn is_error(&self) -> bool
println!; // false
println!; // false
println!; // true
fn encode(&self) -> Vec<u8>
let val = String;
println!; // [43, 79, 75, 230, 173, 163, 13, 10]
fn to_encoded_string(&self) -> io::Result<String>
let val = String;
println!; // "+OK正\r\n"
fn to_beautify_string(&self) -> String
A test result:
1) (Null)
2) (Null Array)
3) OK
4) (Error) Err
5) (Integer) 123
6) \"Bulk String\"
7) (Empty Array)
8) (Buffer) 00 64
9) 1) (Empty Array)
2) (Integer) 123
3) \"Bulk String\"
10) 1) (Null)
2) (Null Array)
3) OK
4) (Error) Err
5) (Integer) 123
6) \"Bulk String\"
7) (Empty Array)
8) (Buffer) 00 64
9) 1) (Empty Array)
2) (Integer) 123
3) \"Bulk String\"
11) (Null)
12) 1) (Null)
2) (Null Array)
3) OK
4) (Error) Err
5) (Integer) 123
6) \"Bulk String\"
7) (Empty Array)
8) (Buffer) 00 64
9) 1) (Empty Array)
2) (Integer) 123
3) \"Bulk String\"
10) 1) (Null)
2) (Null Array)
3) OK
4) (Error) Err
5) (Integer) 123
6) \"Bulk String\"
7) (Empty Array)
8) (Buffer) 00 64
9) 1) (Empty Array)
2) (Integer) 123
3) \"Bulk String\"
11) (Null)
13) (Null)
encode
Encode a RESP value to buffer.
fn encode(value: &Value) -> Vec<u8>
let val = String;
println!; // [43, 79, 75, 230, 173, 163, 13, 10]
encode_slice
Encode a slice of string to RESP request buffer. It is usefull for redis client to encode request command.
fn encode_slice(array: &[&str]) -> Vec<u8>
let array = ;
println!;
// Ok("*3\r\n$3\r\nSET\r\n$1\r\na\r\n$1\r\n1\r\n")
Decoder
Decode redis reply buffers.
Examples
let mut decoder = new;
let buf = NullArray.encode;
println!; // Ok(())
println!; // Some(Value::NullArray)
impl Decoder
fn new() -> Self
let mut decoder = new;
fn with_buf_bulk() -> Self
let mut decoder = with_buf_bulk;
fn feed(&mut self, buf: &[u8]) -> Result<(), io:Error>
println!; // Ok(())
fn read(&mut self) -> Option<Value>
println!; // Some(Value::NullArray)
println!; // None
fn buffer_len(&self) -> usize
println!; // 0
fn result_len(&self) -> usize
println!; // 0